#!/bin/sh

. /etc/conf.d/status
. /etc/conf.d/main.conf
. /etc/conf.d/static_network.conf

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/freon/bin:/freon/sbin
export LD_LIBRARY_PATH=/lib:/lib64:/usr/lib:/freon/lib:/freon/lib64:/freon/lib/x86_64-linux-gnu

# clear
clear

# Welcome message!
echo "Welcome to Freon Linux!"

# mount proc on boot
echo -n "Mounting /proc..."
/bin/mount -t proc proc /proc -o nosuid,noexec,nodev
status

# mount /sys
echo -n "Mounting /sys..."
/bin/mount -t sysfs sys /sys -o nosuid,noexec,nodev
status

# mount devpts
echo -n "Mounting /dev/pts..."
/bin/mount -t devpts /dev/pts
status

# Remount rootfs with read and write
echo -n "Remounting rootfs... "
/bin/mount -o remount,rw / > /dev/null
status

echo -n "Checking some local paths..."

# Check if mtab is linked to mounts
if [ ! -L /etc/mtab ]; then
  ln -s /proc/mounts /etc/mtab
fi

# Check to see if keymap exists
if [ ! -f /share/kmap/$KMAP.kmap ]; then
  /bin/dumpkmap > /share/kmap/$KMAP.kmap
fi

status

# Deal with mdev
/sbin/mdev -s
echo /sbin/mdev > /proc/sys/kernel/hotplug

# Set hostname
echo -n "Setting hostname... "
/bin/hostname -F /etc/hostname > /dev/null
status

# Configure network loopback
echo -n "Configuring network loopback... "
/sbin/ifconfig lo 127.0.0.1 up
/sbin/route add 127.0.0.1 lo
status

# Get eth0 linked up
echo -n "Prepare $NETINTERFACE... "
/sbin/ifconfig $NETINTERFACE up > /dev/null
status

# Start network
if [ "$NETTYPE" = "dynamic" ] ; then
  echo -n "Starting UDHCPC... "
  /sbin/udhcpc -b -i $NETINTERFACE -p /var/run/udhcpc.$NETINTERFACE.pid > /dev/null
  status
else
  echo -n "Static IP set, starting $IP on $NETINTERFACE... "
  /sbin/ifconfig $NETINTERFACE $IP netmask $MASK up
  /sbin/route add default gateway $GATEWAY
  echo -n "nameserver $DNS_SERVER" > /etc/resolv.conf
fi

echo -n "Loading Keymap..."
/sbin/loadkmap < /share/kmap/$KMAP.kmap
status

/etc/init.d/dropbear start

/etc/init.d/chttpd start

export TERM="xterm"
export TERMINFO="/share/terminfo"

# Show login prompt
getty 9600 tty1
